#@head() #@header()
<title>客户列表</title>
#@aside("user")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<style>
	.box-body{padding:5px !important}
</style>
<div class="content-wrapper">
	<section class="content">
	<div class="nav-tabs-custom"> 
		#@usersmenu("realname")
		<div class="tab-content">
		  <div class="tab-pane active" id="tab_1">
				<div class="input-group margin" style="float:left">
					<label style="float:left;margin-top:8px;margin-left:5px;">实名时间：</label>
					<input type="text" id="startime" class="form-control" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width:120px;float:left;margin-left:10px;">
					<span style="float:left;margin:5px 5px 0 5px;">—</span> 
					<input type="text" id="endtime" class="form-control" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width:120px;float:left;margin-right:20px;">
					<label style="float:left;margin-top:8px;margin-left:5px;">真实姓名：</label>
					<input type="text" id="realname" style="width:150px;margin-right:20px;" class="form-control" placeholder="" >
					<label style="float:left;margin-top:8px;margin-left:5px;">用户名：</label>
					<input type="text" id="usermobile" style="width:150px;" class="form-control" placeholder="" >
					<span style="float:left;margin-left:20px;" class="input-group-btn">
					  <button id="seachuser" type="button" class="btn btn-info btn-flat">搜索</button>
					</span>
				</div>
				<table class="table table-bordered" style="clear:both;width:40%;margin-left:10px;">
					<tbody>
					<tr> 
					  <th>用户实名总数：<span id="total_users"></span> 人</th>
					  
					</tr>
				  </tbody>
			    </table>
			<div class="box-body">
				<table  id="example1" class="table table-striped">
					<thead>
						<tr>
							<th>用户ID</th>
							<th>用户名</th>
							<th>真实姓名</th>
							<th>性别</th>
							<th>生日</th>
							<th>身份证号</th>
							<th>实名时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="userlist">
						
					</tbody>
				</table>
				<div class="box-footer clearfix">
				  <ul class="pagination pagination-sm no-margin pull-right">
					<li id="userlist1"><a href="#">首页</a></li>
					<li id="userlist2"><a href="#">上一页</a></li>
					<li><a href="#">第<span id="userlist5"></span>页 共<span id="userlist6"></span>页</a></li>
					<li id="userlist3"><a href="#">下一页</a></li>
					<li id="userlist4"><a href="#">尾页</a></li>
				  </ul>
				</div>
			</div>
			</div>
		</div>
	</div>
	</section>
</div>
#@footer()
<script id="userlistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${id}</td>
		<td>${mobile}</td>
		<td>${real_name}</td>
		<td>${sex}</td>
		<td>${birthday}</td>
		<td>${cert_num}</td>
		<td>${real_name_time}</td>
		<td>
			<div class="btn-group">
			  <button onclick="location.href='#(path)/admin/page/user-userinfo?id=${id}'" type="button" class="btn btn-info">查看</button>
			</div>
		</td>
	</tr>
</script>
<script>
var totalPage = 1;
var pageNumber = 1;
var usermobile = "";
var startime = "";
var endtime = "";
var realname ="";
 $(document).ready(function(){
	pageNumber = 1;
	$("#userlist").empty();
	userlist(pageNumber,usermobile,startime,endtime,realname);
	$("#userlist5").html(pageNumber);
});
$("#userlist1").click(function(){
	$("#userlist").empty();
	pageNumber = 1;
	userlist(pageNumber,usermobile,startime,endtime,realname);
	$("#userlist5").html(pageNumber);
});
$("#userlist2").click(function(){
	if(pageNumber==1){
		alert("当前页是首页!");
	}else{
	$("#userlist").empty();
	pageNumber = pageNumber-1;
	userlist(pageNumber,usermobile,startime,endtime,realname);
	$("#userlist5").html(pageNumber);
	}
});
$("#userlist3").click(function(){
	if(pageNumber==totalPage){
		alert("当前页是尾页!");
	}else{
	$("#userlist").empty();
	pageNumber = pageNumber +1;
	userlist(pageNumber,usermobile,startime,endtime,realname);
	$("#userlist5").html(pageNumber);
	}
});
$("#userlist4").click(function(){
	$("#userlist").empty();
	pageNumber = totalPage;
	userlist(pageNumber,usermobile,startime,endtime,realname);
	$("#userlist5").html(pageNumber);
});
$("#seachuser").click(function(){
	startime = $("#startime").val();
	endtime = $("#endtime").val(); 
	$("#userlist").empty();
	usermobile = $("#usermobile").val();
	realname = $("#realname").val();
	pageNumber = 1;
	userlist(pageNumber,usermobile,startime,endtime,realname);
	$("#userlist5").html(pageNumber);
});
function userlist(pageNumber,usermobile,startime,endtime,realname){
	$.getJSON("/user/list?token=#(session.token??)&page="+pageNumber+"&size=12&isRealNameVerify=1&mobile="+usermobile+"&realNameTimeStart="+startime+"&realNameTimeEnd="+endtime+"&realName="+realname, function(userli) {
		$("#total_users").html(userli.data.page.totalRow);
		totalPage = userli.data.page.totalPage;
		$("#userlist6").html(totalPage);
		$.each(userli.data.page.list, function(i, item){ 
			if(item.status=="1"){
				var status = "正常";
			}
			if(item.status=="0"){
				var status = "禁用";
			}
			if(!$.isBlank(item.cert_num)){
				var birthday = item.cert_num;
				var birthday=item.birthday;
				if(item.sex == 1){sex = "男";} else if(item.sex == 2){sex = "女";}
			}
			var now = getNowFormatDate();
			var days = DateDiff(item.create_time,now);
			var userlist = {mobile:item.mobile,real_name_time:item.real_name_time,code:item.code,id:item.id,real_name:item.real_name,cert_num:item.cert_num,birthday:birthday,sex:sex};
			$("#userlistall").tmpl(userlist).appendTo('#userlist');
		});
	});	
}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}
function  DateDiff(sDate1,  sDate2){    //sDate1和sDate2是2006-12-18格式  
       var  aDate,  oDate1,  oDate2,  iDays  
       aDate  =  sDate1.split("-")  
       oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])    //转换为12-18-2006格式  
       aDate  =  sDate2.split("-")  
       oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])  
       iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数  
       return  iDays  
}    
</script> 


</body>
</html>

